using System;
using System.Collections;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class LengthCollectionRuleAttributeTest
    {

        private const int expectedMaximum = 3;



        [Test]
        [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Minimum too low.\r\nParameter name: value")]
        public void MinimumTooSmall()
        {
            const int expectedMinimum = -1;
            var ruleAttribute = new LengthCollectionRuleAttribute(expectedMaximum) {Minimum = expectedMinimum};
        }

        [Test]
        public void CheckValues()
        {
            var ruleAttribute = new LengthCollectionRuleAttribute(expectedMaximum);
            Assert.IsFalse(ruleAttribute.ExcludeDuplicatesFromCount);
            Assert.AreEqual(expectedMaximum, ruleAttribute.Maximum);

            var propertyRule = (LengthCollectionRule)ruleAttribute.CreateInstance(new MockPropertyDescriptor<IList>("foo"));
            var parameterRule = (LengthCollectionRule)ruleAttribute.CreateInstance(new MockParameterDescriptor<IList>("foo"));
            var fieldRule = (LengthCollectionRule)ruleAttribute.CreateInstance(new MockFieldDescriptor<IList>("foo"));

            Assert.AreEqual(expectedMaximum, propertyRule.Maximum);
            Assert.IsFalse(propertyRule.ExcludeDuplicatesFromCount);

            Assert.IsFalse(parameterRule.ExcludeDuplicatesFromCount);
            Assert.AreEqual(expectedMaximum, parameterRule.Maximum);

            Assert.IsFalse(fieldRule.ExcludeDuplicatesFromCount);
            Assert.AreEqual(expectedMaximum, fieldRule.Maximum);

            ruleAttribute.ExcludeDuplicatesFromCount = true;

        }


        [Test]
        public void CallAttributeTester()
        {
            AttributeTester.CheckDefaultValues<IList>(new LengthCollectionRuleAttribute(expectedMaximum), true, true, true);
            AttributeTester.CheckNonDefaultValues<IList>(new LengthCollectionRuleAttribute(expectedMaximum), true, true, true);
        }

    }
}